package co.baiku.boot.request;


import co.baiku.boot.common.tools.ObjectTools;

import java.util.HashMap;
import java.util.Map;

/**
 * 退款请求
 * <a href='https://pay.weixin.qq.com/wiki/doc/api/jsapi_sl.php?chapter=9_4'>官方文档</a>
 */
public class WeixinRefundRequest implements WeixinPayRequest {

    public WeixinRefundRequest() {
    }

    public WeixinRefundRequest(String transaction_id, Integer refund_fee, String out_trade_no, String out_refund_no, Integer total_fee) {
        this(transaction_id, refund_fee, "", out_trade_no, out_refund_no, total_fee, "");
    }

    public WeixinRefundRequest(String transaction_id, Integer refund_fee, String refund_desc, String out_trade_no, String out_refund_no, Integer total_fee, String notify_url) {
        this.transaction_id = transaction_id;
        this.total_fee = refund_fee;
        this.refund_desc = refund_desc;
        this.out_trade_no = out_trade_no;
        this.out_refund_no = out_refund_no;
        this.notify_url = notify_url;
        this.total_fee = total_fee;
    }

    @Override
    public Map<String, String> toMap() {
        Map<String, String> data = new HashMap<>();
        data.put("transaction_id", transaction_id);
        data.put("out_trade_no", out_trade_no);
        data.put("out_refund_no", out_refund_no);
        data.put("total_fee", String.valueOf(total_fee));
        data.put("refund_fee", String.valueOf(refund_fee));
        data.put("refund_desc", refund_desc);
        data.put("refund_fee_type", refund_fee_type);
        data.put("notify_url", notify_url);
        data.put("sub_mch_id", sub_mch_id);
        return ObjectTools.removeNull(data);
    }

    /**
     * 微信订单号
     */
    private String transaction_id;
    /**
     * 申请退款金额
     * <p>
     * 退款总金额，单位为分，只能为整数，可部分退款。
     * </p>
     */
    private Integer refund_fee;
    /**
     * 退款原因
     * <p>
     * 若商户传入，会在下发给用户的退款消息中体现退款原因<br/>
     * 注意：若订单退款金额≤1元，且属于部分退款，则不会在退款消息中体现退款原因
     * </p>
     */
    private String refund_desc;

    /**
     * 子商户公众账号ID(选填)
     * <p>
     * 微信分配的子商户公众账号ID，如需在支付完成后获取sub_openid则此参数必传。
     * </p>
     */
    private String sub_appid;
    /**
     * 子商户号(支付服务商时必填)
     * <p>
     * 微信支付分配的子商户号
     * </p>
     */
    private String sub_mch_id;

    /**
     * 商户订单号(必填)
     * <p>商户系统内部订单号，要求32个字符内，只能是数字、大小写字母_-|*且在同一个商户号下唯一。<a href='https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_sl_api.php?chapter=4_2'>详见商户订单号</a></p>
     */
    private String out_trade_no;
    /**
     * 商户退款单号(必填)
     * <p>商户系统内部的退款单号，商户系统内部唯一，只能是数字、大小写字母_-|*@ ，同一退款单号多次请求只退一笔。</p>
     */
    private String out_refund_no;

    /**
     * 退款货币种类(选填)
     * <p>退款货币类型，需与支付一致，或者不填。符合ISO 4217标准的三位字母代码，默认人民币：CNY</p>
     */
    private String refund_fee_type = "CNY";

    /**
     * 总金额(必填)
     * <p>订单总金额，只能为整数，详见<a href='https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_sl_api.php?chapter=4_2'>支付金额</a></p>
     */
    private Integer total_fee;


    /**
     * 通知地址
     * <p>
     * 异步接收微信支付退款结果通知的回调地址，通知URL必须为外网可访问的url，不允许带参数,如果参数中传了notify_url，则商户平台上配置的回调地址将不会生效。
     * </p>
     */
    private String notify_url;

    public String getSub_mch_id() {
        return sub_mch_id;
    }

    public void setSub_mch_id(String sub_mch_id) {
        this.sub_mch_id = sub_mch_id;
    }

    public String getSub_appid() {
        return sub_appid;
    }

    public void setSub_appid(String sub_appid) {
        this.sub_appid = sub_appid;
    }

    public String getOut_trade_no() {
        return out_trade_no;
    }

    public void setOut_trade_no(String out_trade_no) {
        this.out_trade_no = out_trade_no;
    }

    public String getOut_refund_no() {
        return out_refund_no;
    }

    public void setOut_refund_no(String out_refund_no) {
        this.out_refund_no = out_refund_no;
    }

    public String getRefund_fee_type() {
        return refund_fee_type;
    }

    public void setRefund_fee_type(String refund_fee_type) {
        this.refund_fee_type = refund_fee_type;
    }

    public Integer getTotal_fee() {
        return total_fee;
    }

    public void setTotal_fee(Integer total_fee) {
        this.total_fee = total_fee;
    }

    public String getNotify_url() {
        return notify_url;
    }

    public void setNotify_url(String notify_url) {
        this.notify_url = notify_url;
    }

    public String getTransaction_id() {
        return transaction_id;
    }

    public void setTransaction_id(String transaction_id) {
        this.transaction_id = transaction_id;
    }

    public Integer getRefund_fee() {
        return refund_fee;
    }

    public void setRefund_fee(Integer refund_fee) {
        this.refund_fee = refund_fee;
    }

    public String getRefund_desc() {
        return refund_desc;
    }

    public void setRefund_desc(String refund_desc) {
        this.refund_desc = refund_desc;
    }
}
